function Range(start, end) {
	this.start = start;
	this.end = end;
}

Range.prototype.getValueInRange = function(value) {
	return Math.min(this.end, Math.max(this.start, value));
};

// ----------------- DragHelper ------------------
/**
 * Helper to receive Dragging events.
 * 
 * @param jqElement
 *            draggable jQuery element
 * @param dragHandler
 *            handler that that receives the dragging events. Must have onDrag and onDragEnd methods.
 * 
 * @returns this
 */
function DragHelper(jqElement, dragHandler) {
	this.jqElement = jqElement;
	this.mousedown = false;

	this.dragHandler = {
		onDrag : function() {
		},
		onDragEnd : function() {
		}
	};
	jQuery.extend(this.dragHandler, dragHandler);
}

DragHelper.prototype.register = function() {
	var self = this;

	this.jqElement.on('mousedown', function(event) {
		self.mousedown = true;
		self.updateOrigin(event);

		return false;
	});

	$(document).on('mousemove', function(event) {
		if (self.mousedown) {
			var dx = event.pageX - self.origin.x;
			var dy = event.pageY - self.origin.y;

			self.dragHandler.onDrag(dx, dy);

			self.updateOrigin(event);
		}
	});

	$(document).on('mouseup', function(event) {
		if (self.mousedown) {
			var dx = event.pageX - self.origin.x;
			var dy = event.pageY - self.origin.y;

			self.dragHandler.onDragEnd(dx, dy);
		}
		self.mousedown = false;
	});
};

DragHelper.prototype.updateOrigin = function(event) {
	this.origin = {
		x : event.pageX,
		y : event.pageY
	};
};